using System;
using LS.Saving;
using UnityEngine;
using Unity.VisualScripting;

namespace LS.VisualScripting
{
    public class Load : SavingUnit
    {
        [DoNotSerialize]
        public ValueInput GroupName { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            Requirement(GroupName, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string groupName = flow.GetValue<string>(GroupName);
            LSEntry.Saving.Load(groupName);
            return base.In(flow);
        }
    }
    
    public class LoadByFileName : SavingUnit
    {
        [DoNotSerialize]
        public ValueInput FileName { get; set; }
        
        [DoNotSerialize]
        public ValueInput GroupName { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            FileName = ValueInput<string>(nameof(FileName), string.Empty);
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            Requirement(FileName, Input);
            Requirement(GroupName, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string name =  flow.GetValue<string>(FileName);
            string groupName = flow.GetValue<string>(GroupName);
            LSEntry.Saving.Load(groupName, name);
            return base.In(flow);
        }
    }
    
    public class LoadByFile : SavingUnit
    {
        [DoNotSerialize]
        public ValueInput File { get; set; }
        
        [DoNotSerialize]
        public ValueInput GroupName { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            File = ValueInput<IDataFile>(nameof(File));
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            Requirement(File, Input);
            Requirement(GroupName, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            IDataFile file =  flow.GetValue<IDataFile>(File);
            string groupName = flow.GetValue<string>(GroupName);
            LSEntry.Saving.Load(groupName, file);
            return base.In(flow);
        }
    }
}